package com.feihong.yw189.utils;

import android.annotation.SuppressLint;
import android.text.TextUtils;
import android.util.Log;

import com.feihong.yw189.app.App;
import com.feihong.yw189.bluetooth.utils.util.ConstantsValue;
import com.feihong.yw189.bluetooth.utils.util.PrefUtils;
import com.feihong.yw189.model.User.UserEntity;
import com.iflytek.cloud.thirdparty.S;


/**
 * Created by Sabirjan on 2017/6/15.
 * TXGW.
 * 飞宏电子
 */

public class UserLoginInfo {

    /**
     * 用户id
     */
    private static final String USER_ID = "USER_ID";
    /**
     * 用户名
     */
    private static final String USER_NAME = "USER_NAME";
    /**
     * 用户邮箱
     */
    private static final String USER_EMAIL = "USER_EMAIL";
    /**
     * 用户绑定的手机号(区别于用户的联系方式)
     */
    private static final String USER_MOBILE = "USER_MOBILE";
    /**
     * 用户类型(个人用户/企业用户)
     */
    private static final String USER_TYPE = "USER_TYPE";
    /**
     * 用户的账户状态
     */
    private static final String USER_ACCOUNT_STATUS = "USER_ACCOUNT_STATUS";
    /**
     * 活体检测标识  1 开启  2 关闭
     */
    private static final String USER_FACE_READ_SIGN = "USER_FACE_READ_SIGN";
    /**
     * 转账权限     1 正常   2 禁用
     */
    private static final String TRANS_ACCOUNT_PERMISSION = "TRANS_ACCOUNT_PERMISSION";
    /**
     * 转出权限 1 正常   2 禁用
     */
    private static final String TRANS_OUT_PERMISSION = "TRANS_OUT_PERMISSION";
    /**
     * 用户补卡权限       1 正常   2 禁用
     */
    public static final String USER_REISUSE_PERMISSION = "USER_REISUSE_PERMISSION";
    /**
     * 平台电话
     */
    private static final String PLATFORM_TEL = "PLATFORM_TEL";

    /**
     * 用户身份证姓名
     */
    private static final String USER_IDCARD_REAL_NAME = "USER_IDCARD_REAL_NAME";
    /**
     * 用户身份证号码
     */
    private static final String USER_IDCARD_NUM = "USER_IDCARD_NUM";
    /**
     * 性别
     */
    private static final String USER_SEX = "USER_SEX";
    /**
     * 头像
     */
    private static final String USER_PIC = "USER_PIC";
    /**
     * 用户联系电话
     */
    private static final String USER_CONTACT_TEL = "USER_CONTACT_TEL";
    /**
     * 用户qq
     */
    private static final String USER_QQ_ACCOUNT = "USER_QQ_ACCOUNT";
    /**
     * 客户经理电话
     */
    private static final String ACCOUNT_MANAGER_CONTACT_TEL = "ACCOUNT_MANAGER_CONTACT_TEL";
    /**
     * 客户经理名称
     */
    private static final String ACCOUNT_MANAGER_NAME = "ACCOUNT_MANAGER_NAME";
    /**
     * 用户地址
     */
    private static final String USER_CONTACT_ADR = "USER_CONTACT_ADR";
    /**
     * 用户店铺名称
     */
    private static final String USER_STORE_ACCOUNT = "USER_STORE_ACCOUNT";
    /**
     * 用户电子钱包状态
     */
    private static final String USER_WALLET_STATUS = "USER_WALLET_STATUS";
    /**
     * 用户的支付宝账户
     */
    private static final String USER_ALIPAR_ACCOUNT = "USER_ALIPAR_ACCOUNT";
    /**
     * 支付宝费率
     */
    private static final String ALIPAY_RATE = "ALIPAY_RATE";
    /**
     * 银行卡号
     */
    private static final String USER_BANKCARD_NUM = "USER_BANK_NUM";
    /**
     * 银行卡的开户名
     */
    private static final String USER_BANK_ACCOUNT_NAME = "USER_BANK_ACCOUNT_NAME";
    /**
     * 银行卡所属银行名称
     */
    private static final String USER_BANKCARD_BANKNAME = "USER_BANKCARD_BANKNAME";
    /**
     * 用户绑定的银行卡所在银行的logo
     */
    private static final String USER_BANK_BANKLOGO = "USER_BANK_BANKLOGO";
    /**
     * 银行卡所属银行费率
     */
    private static final String USER_BANKCARD_RATE = "USER_BANKCARD_RATE";
    /**
     * 用户余额
     */
    private static final String USER_BALANCE = "USER_BALANCE";
    /**
     * 用户冻结资金
     */
    private static final String USER_FREEZING_BALANCE = "USER_FREEZING_BALANCE";
    /**
     * 用户邮箱验证通过标识   1 通过  其他标识为通过
     */
    private static final String USER_VERIFY_EMAIL_SIGN = "USER_VERIFY_EMAIL_SIGN";
    /**
     * 用户手机认证通过标识   1 通过  其他标识为通过
     */
    private static final String USER_VERIFY_MOBILE_SIGN = "USER_VERIFY_MOBILE_SIGN";
    /**
     * 用户实名认证通过标识   1 通过  其他标识为通过
     */
    private static final String USER_VERIFY_REAL_NAME_SIGN = "USER_VERIFY_REAL_NAME_SIGN";
    /**
     * 用户地区ID(市级ID)
     */
    private static final String USER_REGION_ID = "USER_REGION_ID";
    /**
     * 用户地区名称(市级名称)
     */
    private static final String USER_REGION_NAME = "USER_REGION_NAME";
    /**
     * 上级代理id
     */
    private static final String USER_AGENT_ID = "USER_AGENT_ID";
    /**
     * 上级代理名称
     */
    private static final String USER_AGENT_NAME = "USER_AGENT_NAME";
    /**
     * 上级代理联系电话
     */
    private static final String USER_AGENT_TEL = "USER_AGENT_TEL";
    /**
     * 上级代理联系邮箱
     */
    private static final String USER_AGENT_EMAIL = "USER_AGENT_EMAIL";
    /**
     * 上级代理商头像
     */
    private static final String USER_AGENT_IMG = "USER_AGENT_IMG";
    /**
     * 登录时间
     */
    private static final String USER_LOGIN_TIME = "USER_LOGIN_TIME";

    /**
     * 用户token
     */
    private static final String USER_TOKEN = "USER_TOKEN";
    /**
     * 最后更新token时间
     */
    private static final String USER_TOKEN_LAST_UPDATE = "USER_TOKEN_LAST_UPDATE";

    /**
     * 未读消息数量
     */
    private static final String UNREAD_MSG_COUNT = "UNREAD_MSG_COUNT";
    /**
     * 用户当前位置经度
     */
    private static final String USER_LOCATION_LON = "USER_LOCATION_LON";
    /**
     * 用户当前位置维度
     */
    private static final String USER_LOCATION_LAT = "USER_LOCATION_LAT";
    private static UserEntity userLoc;

    /**
     * 获取用户的登录状态
     *
     * @return true是已登录 ，false 是未登录
     */
    public boolean isUserLogin() {

        if (getUserToken().isEmpty()) {
            return false;
        }
        return true;
    }

    private static UserLoginInfo userLoginInfo = new UserLoginInfo();

    public static UserLoginInfo getUserLoginInfoInstance() {
        userLoginInfo.getUserLoc();
        return userLoginInfo;
    }

    private UserLoginInfo() {
    }

    /**
     * 获取用户的基本信息
     *
     * @return
     */
    private UserEntity getUserInfo() {
        UserEntity userEntity = new UserEntity();
        userEntity.setUserID(PreferenceTools.getString(USER_ID, null));
        userEntity.setUserName(PreferenceTools.getString(USER_NAME, null));
        userEntity.setUserMobile(PreferenceTools.getString(USER_MOBILE, null));
        userEntity.setUserStatus(PreferenceTools.getString(USER_ACCOUNT_STATUS, null));
        userEntity.setUserEmail(PreferenceTools.getString(USER_EMAIL, null));

        userEntity.setFaceReadSign(PreferenceTools.getString(USER_FACE_READ_SIGN, null));

        userEntity.setUserPic(PreferenceTools.getString(USER_PIC, null));
        userEntity.setUserAccountBalance(PreferenceTools.getString(USER_BALANCE, null));
        userEntity.setUserFreezingBalance(PreferenceTools.getString(USER_FREEZING_BALANCE, null));
        userEntity.setUserType(PreferenceTools.getString(USER_TYPE, null));
        userEntity.setTransToAccountPermission(PreferenceTools.getString(TRANS_ACCOUNT_PERMISSION, null));
        userEntity.setBalaceTransOutPermission(PreferenceTools.getString(TRANS_OUT_PERMISSION, null));
        userEntity.setReissueCardPermission(PreferenceTools.getString(USER_REISUSE_PERMISSION, null));
        userEntity.setPlatFormTel(PreferenceTools.getString(PLATFORM_TEL, null));
        userEntity.setUserIDCardName(PreferenceTools.getString(USER_IDCARD_REAL_NAME, null));
        userEntity.setUserIDCardNum(PreferenceTools.getString(USER_IDCARD_NUM, null));
        userEntity.setUserSex(PreferenceTools.getString(USER_SEX, null));
        userEntity.setUserTel(PreferenceTools.getString(USER_CONTACT_TEL, null));
        userEntity.setUsrQQ(PreferenceTools.getString(USER_QQ_ACCOUNT, null));
        userEntity.setUserAccountManagerContactTel(PreferenceTools.getString(ACCOUNT_MANAGER_CONTACT_TEL, null));
        userEntity.setUserAccountManagerName(PreferenceTools.getString(ACCOUNT_MANAGER_NAME, null));
        userEntity.setUsrAdr(PreferenceTools.getString(USER_CONTACT_ADR, null));
        userEntity.setUserStoreAccount(PreferenceTools.getString(USER_STORE_ACCOUNT, null));
        userEntity.setUserWalletStatus(PreferenceTools.getString(USER_WALLET_STATUS, null));
        userEntity.setUserAliPayAccount(PreferenceTools.getString(USER_ALIPAR_ACCOUNT, null));
        userEntity.setAliPayRate(PreferenceTools.getString(ALIPAY_RATE, null));
        userEntity.setUserBankNum(PreferenceTools.getString(USER_BANKCARD_NUM, null));
        userEntity.setUserBankName(PreferenceTools.getString(USER_BANKCARD_BANKNAME, null));
        userEntity.setUserBankCardAccountName(PreferenceTools.getString(USER_BANK_ACCOUNT_NAME, null));
        userEntity.setUserBankRate(PreferenceTools.getString(USER_BANKCARD_RATE, null));
        userEntity.setUserVerifyEmailSign(PreferenceTools.getString(USER_VERIFY_EMAIL_SIGN, null));
        userEntity.setUserVerifyMobileSign(PreferenceTools.getString(USER_VERIFY_MOBILE_SIGN, null));
        userEntity.setUserVerifyRealNameSign(PreferenceTools.getString(USER_VERIFY_REAL_NAME_SIGN, null));
        userEntity.setUserRegionID(PreferenceTools.getString(USER_REGION_ID, null));
        userEntity.setUserReginName(PreferenceTools.getString(USER_REGION_NAME, null));
        userEntity.setUserAgentUserID(PreferenceTools.getString(USER_AGENT_ID, null));
        userEntity.setUserAgentUserName(PreferenceTools.getString(USER_AGENT_NAME, null));
        userEntity.setUserAgentTel(PreferenceTools.getString(USER_AGENT_TEL, null));
        userEntity.setUserAgentUserEmail(PreferenceTools.getString(USER_AGENT_EMAIL, null));
        userEntity.setUserAgentUserImg(PreferenceTools.getString(USER_AGENT_IMG, null));
        userEntity.setBankLogo(PreferenceTools.getString(USER_BANK_BANKLOGO, null));
        userEntity.setUserLon(PreferenceTools.getString(USER_LOCATION_LON,null));
        userEntity.setUserLat(PreferenceTools.getString(USER_LOCATION_LAT,null));
        return userEntity;
    }

    /**
     * 获取当前用户ID
     *
     * @return
     */
    public String getUserId() {
        if (!isUserLogin()) {
            return "";
        }
        return PreferenceTools.getString(USER_ID, "");
    }


    public String getUserToken() {
        return PreferenceTools.getString(USER_TOKEN, "");
    }

    /**
     * 保存用户的登录基本信息
     *
     * @param user 用户信息: 电话号码,登录时间,性别，积分，token。。。。。。
     * @return 保存成功返回true ,失败返回false
     *
     * TODO 注意  這很重要  为了避免信息的覆盖  只有从服务端获取的完整的个人信息 才能调用此方法(一般是登录接口)
     */
    @SuppressLint("LongLogTag")
    public boolean saveUserLoginInfo(UserEntity user) {
        if (user == null) {
            return false;
        }
        String userName = user.getUserName();
        if (DxTextUtils.isEmpty(userName)) {
            userName = "";
        }
        PreferenceTools.putString(USER_NAME, userName);

        String userID = user.getUserID();
        if (DxTextUtils.isEmpty(userID)) {
            userID = "";
        }
        PreferenceTools.putString(USER_ID, userID);

        String userMobild = user.getUserMobile();
        if (DxTextUtils.isEmpty(userMobild)) {
            userMobild = "";
        }
        PreferenceTools.putString(USER_MOBILE, userMobild);

        String userStatus = user.getUserStatus();
        if (DxTextUtils.isEmpty(userStatus)) {
            userStatus = "";
        }
        PreferenceTools.putString(USER_ACCOUNT_STATUS,userStatus);

        String email = user.getUserEmail();
        if (DxTextUtils.isEmpty(email)) {
            email = "";
        }
        PreferenceTools.putString(USER_EMAIL, email);

        String faceReadSign = user.getFaceReadSign();
        if (DxTextUtils.isEmpty(faceReadSign)) {
            faceReadSign = "";
        }
        PreferenceTools.putString(USER_FACE_READ_SIGN, faceReadSign);

        String userType = user.getUserType();
        if (DxTextUtils.isEmpty(userType)) {
            userType = "";
        }
        PreferenceTools.putString(USER_TYPE, userType);

        String transToAccountPer = user.getTransToAccountPermission();
        if (DxTextUtils.isEmpty(transToAccountPer)) {
            transToAccountPer = "";
        }
        PreferenceTools.putString(TRANS_ACCOUNT_PERMISSION, transToAccountPer);

        String userBalanceTransOutPer = user.getBalaceTransOutPermission();
        if (DxTextUtils.isEmpty(userBalanceTransOutPer)) {
            userBalanceTransOutPer = "";
        }
        PreferenceTools.putString(TRANS_OUT_PERMISSION, userBalanceTransOutPer);

        String reissueCardPer = user.getReissueCardPermission();
        if (DxTextUtils.isEmpty(reissueCardPer)) {
            reissueCardPer = "";
        }
        PreferenceTools.putString(USER_REISUSE_PERMISSION, reissueCardPer);

        String platFormTel = user.getPlatFormTel();
        if (DxTextUtils.isEmpty(platFormTel)) {
            platFormTel = "";
        }
        PreferenceTools.putString(PLATFORM_TEL, platFormTel);

        String userIDCardName = user.getUserIDCardName();
        if (DxTextUtils.isEmpty(userIDCardName)) {
            userIDCardName = "";
        }
        PreferenceTools.putString(USER_IDCARD_REAL_NAME, userIDCardName);

        String userIDCardNum = user.getUserIDCardNum();
        if (DxTextUtils.isEmpty(userIDCardNum)) {
            userIDCardNum = "";
        }
        PreferenceTools.putString(USER_IDCARD_NUM, userIDCardNum);

        String userSex = user.getUserSex();
        if (DxTextUtils.isEmpty(userSex)) {
            userSex = "";
        }
        PreferenceTools.putString(USER_SEX, userSex);

        String userPic = user.getUserPic();
        if (DxTextUtils.isEmpty(userPic)) {
            userPic = "";
        }
        PreferenceTools.putString(USER_PIC, userPic);

        String userTel = user.getUserTel();
        if (DxTextUtils.isEmpty(userTel)) {
            userTel = "";
        }
        PreferenceTools.putString(USER_CONTACT_TEL, userTel);

        String userQQ = user.getUsrQQ();
        if (DxTextUtils.isEmpty(userQQ)) {
            userQQ = "";
        }
        PreferenceTools.putString(USER_QQ_ACCOUNT, userQQ);

        String userAccountManagerContactTel = user.getUserAccountManagerContactTel();
        if (DxTextUtils.isEmpty(userAccountManagerContactTel)) {
            userAccountManagerContactTel = "";
        }
        PreferenceTools.putString(ACCOUNT_MANAGER_CONTACT_TEL, userAccountManagerContactTel);

        String userAccountManagerName = user.getUserAccountManagerName();
        if (DxTextUtils.isEmpty(userAccountManagerName)) {
            userAccountManagerName = "";
        }
        PreferenceTools.putString(ACCOUNT_MANAGER_NAME, userAccountManagerName);

        String userAdr = user.getUsrAdr();
        if (DxTextUtils.isEmpty(userAdr)) {
            userAdr = "";
        }
        PreferenceTools.putString(USER_CONTACT_ADR, userAdr);

        String userStoreAccount = user.getUserStoreAccount();
        if (DxTextUtils.isEmpty(userStoreAccount)) {
            userStoreAccount = "";
        }
        PreferenceTools.putString(USER_STORE_ACCOUNT, userStoreAccount);

        String userWalletStaus = user.getUserWalletStatus();
        if (DxTextUtils.isEmpty(userWalletStaus)) {
            userWalletStaus = "";
        }
        PreferenceTools.putString(USER_WALLET_STATUS, userWalletStaus);

        String userAliPayAccount = user.getUserAliPayAccount();
        if (DxTextUtils.isEmpty(userAliPayAccount)) {
            userAliPayAccount = "";
        }
        PreferenceTools.putString(USER_ALIPAR_ACCOUNT, userAliPayAccount);

        String aliPayRate = user.getAliPayRate();
        if (!DxTextUtils.isEmpty(aliPayRate)) {
            aliPayRate = "";
        }
        PreferenceTools.putString(ALIPAY_RATE, aliPayRate);

        String userBankNum = user.getUserBankNum();
        if (DxTextUtils.isEmpty(userBankNum)) {
            userBankNum = "";
        }
        PreferenceTools.putString(USER_BANKCARD_NUM, userBankNum);

        String userBankCardAccountName = user.getUserBankCardAccountName();
        if (DxTextUtils.isEmpty(userBankCardAccountName)) {
            userBankCardAccountName = "";
        }
        PreferenceTools.putString(USER_BANK_ACCOUNT_NAME, userBankCardAccountName);

        String userBankName = user.getUserBankName();
        if (DxTextUtils.isEmpty(userBankName)) {
            userBankName = "";
        }
        PreferenceTools.putString(USER_BANKCARD_BANKNAME, userBankName);

        String userBankRate = user.getUserBankRate();
        if (!DxTextUtils.isEmpty(userBankRate)) {
            userBankRate = "";
        }
        PreferenceTools.putString(USER_BANKCARD_RATE,userBankRate);

        String userFreezingBalance = user.getUserFreezingBalance();
        if (!DxTextUtils.isEmpty(userFreezingBalance)) {
            userFreezingBalance = "";
        }
        PreferenceTools.putString(USER_FREEZING_BALANCE, userFreezingBalance);

        String userAccountBalance = user.getUserAccountBalance();
        if (DxTextUtils.isEmpty(userAccountBalance)) {
            userAccountBalance = "";
        }
        PreferenceTools.putString(USER_BALANCE, userAccountBalance);

        String userVerifyEmailSign = user.getUserVerifyEmailSign();
        if (DxTextUtils.isEmpty(userVerifyEmailSign)) {
            userVerifyEmailSign = "";
        }
        PreferenceTools.putString(USER_VERIFY_EMAIL_SIGN, userVerifyEmailSign);

        String userVerifyMobileSign = user.getUserVerifyMobileSign();
        if (DxTextUtils.isEmpty(userVerifyMobileSign)) {
            userVerifyMobileSign = "";
        }
        PreferenceTools.putString(USER_VERIFY_MOBILE_SIGN, userVerifyMobileSign);

        String userVerifyRealNameSign = user.getUserVerifyRealNameSign();
        if (DxTextUtils.isEmpty(userVerifyRealNameSign)) {
            userVerifyRealNameSign = "";
        }
        PreferenceTools.putString(USER_VERIFY_REAL_NAME_SIGN, userVerifyRealNameSign);

        String userRegionID = user.getUserRegionID();
        if (DxTextUtils.isEmpty(userRegionID)) {
            userRegionID = "";
        }
        PreferenceTools.putString(USER_REGION_ID, userRegionID);

        String userReginName = user.getUserReginName();
        if (DxTextUtils.isEmpty(userReginName)) {
            userReginName = "";
        }
        PreferenceTools.putString(USER_REGION_NAME, userReginName);

        String userAgentUserID = user.getUserAgentUserID();
        if (DxTextUtils.isEmpty(userAgentUserID)) {
            userAgentUserID = "";
        }
        PreferenceTools.putString(USER_AGENT_ID, userAgentUserID);

        String userAgentUserName = user.getUserAgentUserName();
        if (DxTextUtils.isEmpty(userAgentUserName)) {
            userAgentUserName = "";
        }
        PreferenceTools.putString(USER_AGENT_NAME, userAgentUserName);

        String userAgentTel = user.getUserAgentTel();
        if (DxTextUtils.isEmpty(userAgentTel)) {
            userAgentTel = "";
        }
        PreferenceTools.putString(USER_AGENT_TEL, userAgentTel);

        String userAgentUserEmail = user.getUserAgentUserEmail();
        if (DxTextUtils.isEmpty(userAgentUserEmail)) {
            userAgentUserEmail = "";
        }
        PreferenceTools.putString(USER_AGENT_EMAIL, userAgentUserEmail);

        String userAgentUserImg = user.getUserAgentUserImg();
        if (DxTextUtils.isEmpty(userAgentUserImg)) {
            userAgentUserImg = "";
        }
        PreferenceTools.putString(USER_AGENT_IMG, userAgentUserImg);

        String userLat = user.getUserLat();
        if(DxTextUtils.isEmpty(userLat)){
            userLat = "";
        }
        PreferenceTools.putString(USER_LOCATION_LAT,userLat);

        String userLon = user.getUserLon();
        if(DxTextUtils.isEmpty(userLon)){
            userLon = "";
        }
        PreferenceTools.putString(USER_LOCATION_LON,userLon);

        PreferenceTools.putString(USER_LOGIN_TIME, System.currentTimeMillis() + "");

        //更新本地user
        updateUserLoc();

        return true;
    }

    /**
     * 用户登录退出(本地保存的基本信息清理)
     *
     * @return 成功退出返回true，否则返回false
     */
    public boolean userExitLogin() {
        return PreferenceTools.clear();
    }

    /**
     * 更新用户的token信息
     *
     * @param newtoken 新的token
     * @return 成功更新返回true，否则返回false
     * TODO   不可直接调用 此方法仅可以用RefreshToken调用
     */
    public boolean updateUserToken(String newtoken) {

        PreferenceTools.putString(USER_TOKEN, newtoken);
        PreferenceTools.putString(USER_TOKEN_LAST_UPDATE, System.currentTimeMillis() + "");
        if (TextUtils.isEmpty(newtoken)) {
            //token == 空时 清楚本地的指纹信息 ，相当于退出重新登录一样。
            try {
                PrefUtils.setString(App.getApp().getApplication(), ConstantsValue.ZHIWEN_KEY, "");
                PrefUtils.setBoolean(App.getApp().getApplication(), ConstantsValue.ZHIWEN_STATE, false);
            } catch (Exception e) {
                Log.e("项目异常", "------updateUserToken------" + e.toString());
            }
        }
        return true;
    }

    //更新本地user
    public void updateUserLoc() {
        userLoc = getUserInfo();
    }

    //得到本地user信息
    public UserEntity getUserLoc() {
        if (userLoc != null) {
            return userLoc;
        } else {
            userLoc = getUserInfo();
        }
        return userLoc;
    }

    /**
     * 待定
     *
     * @return
     */
    public int getReadInfoNum() {
        return PreferenceTools.getInt("ReadInfo", 0);
    }

    /**
     * 设置用户电话
     *
     * @param userPhone
     * @return
     */
    public boolean setUserMobile(String userPhone) {
        if (DxTextUtils.isEmpty(userPhone)) {
            userPhone = null;
        }
        userLoc.setUserMobile(userPhone);
        PreferenceTools.getString(USER_MOBILE, userPhone);
        return true;
    }

    /**
     * 设置用户ID
     *
     * @param userID
     * @return
     */
    public boolean setUserID(String userID) {
        if (DxTextUtils.isEmpty(userID)) {
            userID = null;
        }
        userLoc.setUserID(userID);
        PreferenceTools.putString(USER_ID, userID);
        return true;
    }

    /**
     * 设置用户名称
     *
     * @param userName
     * @return
     */
    public boolean setUserName(String userName) {
        if (DxTextUtils.isEmpty(userName)) {
            userName = null;
        }
        userLoc.setUserName(userName);
        PreferenceTools.putString(USER_NAME, userName);
        return true;
    }

    /**
     * 设置用户头像链接
     *
     * @param usrPic
     * @return
     */
    public boolean setUserPic(String usrPic) {
        if (DxTextUtils.isEmpty(usrPic)) {
            usrPic = null;
        }
        userLoc.setUserPic(usrPic);
        PreferenceTools.putString(USER_PIC, usrPic);
        return true;
    }

    /**
     * 设置用户状态
     *
     * @param accountStatus
     * @return
     */
    public boolean setUserAccountStatus(String accountStatus) {
        if (DxTextUtils.isEmpty(accountStatus)) {
            accountStatus = null;
        }
        userLoc.setUserStatus(accountStatus);
        PreferenceTools.putString(USER_ACCOUNT_STATUS, accountStatus);
        return true;
    }

    /**
     * 设置用户email
     *
     * @param userEmail
     * @return
     */
    public boolean setUserEMail(String userEmail) {
        if (DxTextUtils.isEmpty(userEmail)) {
            userEmail = null;
        }
        userLoc.setUserEmail(userEmail);
        PreferenceTools.putString(USER_EMAIL, userEmail);
        return true;
    }

    /**
     * 设置用户人脸认证标识
     *
     * @param faceReadSign
     * @return
     */
    public boolean setUserFaceReadSign(String faceReadSign) {
        if (DxTextUtils.isEmpty(faceReadSign)) {
            faceReadSign = null;
        }
        userLoc.setFaceReadSign(faceReadSign);
        PreferenceTools.putString(USER_FACE_READ_SIGN, faceReadSign);
        return true;
    }

    /**
     * 设置用户冻结余额
     *
     * @param freezingBalance
     * @return
     */
    public boolean setUserFreezingBalance(String freezingBalance) {
        if (DxTextUtils.isEmpty(freezingBalance)) {
            freezingBalance = null;
        }
        userLoc.setUserFreezingBalance(freezingBalance);
        PreferenceTools.putString(USER_FREEZING_BALANCE, freezingBalance);
        return true;
    }

    /**
     * 设置用户余额
     *
     * @param balance
     * @return
     */
    public boolean setUsrBalance(String balance) {
        if (DxTextUtils.isEmpty(balance)) {
            balance = null;
        }
        userLoc.setUserAccountBalance(balance);
        PreferenceTools.putString(USER_BALANCE, balance);
        return true;
    }

    /**
     * 用户类型
     *
     * @param userTypeName
     * @return
     */
    public boolean setUserTypeName(String userTypeName) {
        if (DxTextUtils.isEmpty(userTypeName)) {
            userTypeName = null;
        }
        userLoc.setUserType(userTypeName);
        PreferenceTools.putString(USER_TYPE, userTypeName);
        return true;
    }

    /**
     * 用户转账权限
     *
     * @param TAP
     * @return
     */
    public boolean setTransAccountPermission(String TAP) {
        if (TextUtils.isEmpty(TAP)) {
            TAP = null;
        }
        userLoc.setTransToAccountPermission(TAP);
        PreferenceTools.putString(TRANS_ACCOUNT_PERMISSION, TAP);
        return true;
    }

    /**
     * 用户转出权限
     *
     * @param TOP
     * @return
     */
    public boolean setTransOutPermission(String TOP) {
        if (DxTextUtils.isEmpty(TOP)) {
            TOP = null;
        }
        userLoc.setBalaceTransOutPermission(TOP);
        PreferenceTools.putString(TRANS_OUT_PERMISSION, TOP);
        return true;
    }

    /**
     * 补卡权限
     *
     * @param URP
     * @return
     */
    public boolean setUserReisusePer(String URP) {
        if (DxTextUtils.isEmpty(URP)) {
            URP = null;
        }
        userLoc.setReissueCardPermission(URP);
        PreferenceTools.putString(USER_REISUSE_PERMISSION, URP);
        return true;
    }

    /**
     * 平台电话
     *
     * @param platFormTel
     * @return
     */
    public boolean setPlatFormTle(String platFormTel) {
        if (DxTextUtils.isEmpty(platFormTel)) {
            platFormTel = null;
        }
        userLoc.setPlatFormTel(platFormTel);
        PreferenceTools.putString(PLATFORM_TEL, platFormTel);
        return true;
    }


    /**
     * 用户的真实姓名
     *
     * @param usrRealName
     * @return
     */
    public boolean setUserRealName(String usrRealName) {
        if (DxTextUtils.isEmpty(usrRealName)) {
            usrRealName = null;
        }
        userLoc.setUserIDCardNum(usrRealName);
        PreferenceTools.putString(USER_IDCARD_REAL_NAME, usrRealName);
        return true;
    }

    /**
     * 用户的身份证号码
     *
     * @param userIDCardNum
     * @return
     */
    public boolean setUserIDCardNum(String userIDCardNum) {
        if (DxTextUtils.isEmpty(userIDCardNum)) {
            userIDCardNum = null;
        }
        userLoc.setUserIDCardNum(userIDCardNum);
        PreferenceTools.putString(USER_IDCARD_NUM, userIDCardNum);
        return true;
    }

    /**
     * 用户性别
     *
     * @param userSex
     * @return
     */
    public boolean setUserSex(String userSex) {
        if (DxTextUtils.isEmpty(userSex)) {
            userSex = null;
        }
        userLoc.setUserSex(userSex);
        PreferenceTools.putString(USER_SEX, userSex);
        return true;
    }

    /**
     * 用户的联系电话
     *
     * @param userContactTel
     * @return
     */
    public boolean setUserContactTel(String userContactTel) {
        if (DxTextUtils.isEmpty(userContactTel)) {
            userContactTel = null;
        }
        userLoc.setUserTel(userContactTel);
        PreferenceTools.putString(USER_CONTACT_TEL, userContactTel);
        return true;
    }


    /**
     * 储存用户QQ
     *
     * @param userQQ
     * @return
     */
    public boolean setUserQQ(String userQQ) {
        if (DxTextUtils.isEmpty(userQQ)) {
            userQQ = null;
        }
        userLoc.setUsrQQ(userQQ);
        PreferenceTools.putString(USER_QQ_ACCOUNT, userQQ);
        return true;
    }

    /**
     * 设置上级代理ID
     *
     * @param agentID
     * @return
     */
    public boolean setAgentID(String agentID) {
        if (DxTextUtils.isEmpty(agentID)) {
            agentID = null;
        }
        userLoc.setUserAgentUserID(agentID);
        PreferenceTools.putString(USER_AGENT_ID, agentID);
        return true;
    }

    /**
     * 客户经理联系方式
     *
     * @param tel
     * @return
     */
    public boolean setAccountManagerTel(String tel) {
        if (DxTextUtils.isEmpty(tel)) {
            tel = null;
        }
        userLoc.setUserAccountManagerContactTel(tel);
        PreferenceTools.putString(ACCOUNT_MANAGER_CONTACT_TEL, tel);
        return true;
    }

    /**
     * 客户经理联系方式
     *
     * @param name
     * @return
     */
    public boolean setAccountManagerName(String name) {
        if (DxTextUtils.isEmpty(name)) {
            name = null;
        }
        userLoc.setUserAccountManagerName(name);
        PreferenceTools.putString(ACCOUNT_MANAGER_NAME, name);
        return true;
    }

    /**
     * 用户地址
     *
     * @param adr
     * @return
     */
    public boolean setUserContactAdr(String adr) {
        if (DxTextUtils.isEmpty(adr)) {
            adr = null;
        }
        userLoc.setUsrAdr(adr);
        PreferenceTools.putString(USER_CONTACT_ADR, adr);
        return true;
    }

    /**
     * 店铺名称
     *
     * @param storeAccount
     * @return
     */
    public boolean setUserStoreAccount(String storeAccount) {
        if (DxTextUtils.isEmpty(storeAccount)) {
            storeAccount = null;
        }
        userLoc.setUserStoreAccount(storeAccount);
        PreferenceTools.putString(USER_STORE_ACCOUNT, storeAccount);
        return true;
    }

    /**
     * 设置电子钱包状态
     *
     * @param status
     * @return
     */
    public boolean setWalletStatus(String status) {
        if (DxTextUtils.isEmpty(status)) {
            status = null;
        }
        userLoc.setUserWalletStatus(status);
        PreferenceTools.putString(USER_WALLET_STATUS, status);
        return true;
    }

    /**
     * 用户的支付宝账户
     *
     * @param alipayAccount
     * @return
     */
    public boolean setAliPayAccount(String alipayAccount) {
        if (DxTextUtils.isEmpty(alipayAccount)) {
            alipayAccount = null;
        }
        userLoc.setUserAliPayAccount(alipayAccount);
        PreferenceTools.putString(USER_ALIPAR_ACCOUNT, alipayAccount);
        return true;
    }

    /**
     * 支付宝的费率
     *
     * @param alipayRate
     * @return
     */
    public boolean setAliPayRate(String alipayRate) {
        if (DxTextUtils.isEmpty(alipayRate)) {
            alipayRate = null;
        }
        userLoc.setAliPayRate(alipayRate);
        PreferenceTools.putString(ALIPAY_RATE, alipayRate);
        return true;
    }

    /**
     * 用户 是否进行了实名认证的标识
     *
     * @param bankCardNum
     * @return
     */
    public boolean setUserBankCardNum(String bankCardNum) {
        if (DxTextUtils.isEmpty(bankCardNum)) {
            bankCardNum = null;
        }
        userLoc.setUserBankNum(bankCardNum);
        PreferenceTools.putString(USER_BANKCARD_NUM, bankCardNum);
        return true;
    }

    /**
     * 银行名称
     *
     * @param bankName
     * @return
     */
    public boolean setBankName(String bankName) {
        if (DxTextUtils.isEmpty(bankName)) {
            bankName = null;
        }
        userLoc.setUserBankNum(bankName);
        PreferenceTools.putString(USER_BANKCARD_BANKNAME, bankName);
        return true;
    }

    /**
     * 银行卡开户姓名
     *
     * @param accountName
     * @return
     */
    public boolean setBankAccountName(String accountName) {
        if (DxTextUtils.isEmpty(accountName)) {
            accountName = null;
        }
        userLoc.setUserBankCardAccountName(accountName);
        PreferenceTools.putString(USER_BANK_ACCOUNT_NAME, accountName);
        return true;
    }

    /**
     * 储存银行费率
     *
     * @param bankRate
     * @return
     */
    public boolean setBankRate(String bankRate) {
        if (DxTextUtils.isEmpty(bankRate)) {
            bankRate = null;
        }
        userLoc.setUserBankRate(bankRate);
        PreferenceTools.putString(USER_BANKCARD_RATE, bankRate);
        return true;
    }

    /**
     * 邮箱验证通过标识
     *
     * @param verifyEmailSign
     * @return
     */
    public boolean setUserVerifyEmailSign(String verifyEmailSign) {
        if (DxTextUtils.isEmpty(verifyEmailSign)) {
            verifyEmailSign = null;
        }
        userLoc.setUserVerifyEmailSign(verifyEmailSign);
        PreferenceTools.putString(USER_VERIFY_EMAIL_SIGN, verifyEmailSign);
        return true;
    }

    /**
     * 手机验证通过标识
     *
     * @param verifyMobileSign
     * @return
     */
    public boolean setUserVerifyMobileSign(String verifyMobileSign) {
        if (DxTextUtils.isEmpty(verifyMobileSign)) {
            verifyMobileSign = null;
        }
        userLoc.setUserVerifyMobileSign(verifyMobileSign);
        PreferenceTools.putString(USER_VERIFY_MOBILE_SIGN, verifyMobileSign);
        return true;
    }

    /**
     * 实名认证通过标识
     *
     * @param verifyRealNameSign
     * @return
     */
    public boolean setUserVerifyRealnameSign(String verifyRealNameSign) {
        if (DxTextUtils.isEmpty(verifyRealNameSign)) {
            verifyRealNameSign = null;
        }
        userLoc.setUserVerifyRealNameSign(verifyRealNameSign);
        PreferenceTools.putString(USER_VERIFY_REAL_NAME_SIGN, verifyRealNameSign);
        return true;
    }

    /**
     * 城市ID
     *
     * @param regionID
     * @return
     */
    public boolean setUserRegionID(String regionID) {
        if (DxTextUtils.isEmpty(regionID)) {
            regionID = null;
        }
        userLoc.setUserRegionID(regionID);
        PreferenceTools.putString(USER_REGION_ID, regionID);
        return true;
    }

    /**
     * 城市名称
     *
     * @param regionName
     * @return
     */
    public boolean setUserRegionName(String regionName) {
        if (DxTextUtils.isEmpty(regionName)) {
            regionName = null;
        }
        userLoc.setUserReginName(regionName);
        PreferenceTools.putString(USER_REGION_NAME, regionName);
        return true;
    }

    /**
     * 设置上级代理名称
     *
     * @param agentName
     * @return
     */
    public boolean setAgentName(String agentName) {
        if (DxTextUtils.isEmpty(agentName)) {
            agentName = null;
        }
        userLoc.setUserAgentUserName(agentName);
        PreferenceTools.putString(USER_AGENT_NAME, agentName);
        return true;
    }

    /**
     * 上级代理邮箱
     *
     * @param agentEmail
     * @return
     */
    public boolean setAgentEmail(String agentEmail) {
        if (DxTextUtils.isEmpty(agentEmail)) {
            agentEmail = null;
        }
        userLoc.setUserAgentUserEmail(agentEmail);
        PreferenceTools.putString(USER_AGENT_EMAIL, agentEmail);
        return true;
    }

    /**
     * 上级代理头像
     *
     * @param agentImg
     * @return
     */
    public boolean setAgentImg(String agentImg) {
        if (DxTextUtils.isEmpty(agentImg)) {
            agentImg = null;
        }
        userLoc.setUserAgentUserImg(agentImg);
        PreferenceTools.putString(USER_AGENT_IMG, agentImg);
        return true;
    }

    /**
     * 储存上级代理联系电话
     *
     * @param agentTel
     * @return
     */
    public boolean setAgetnTel(String agentTel) {
        if (DxTextUtils.isEmpty(agentTel)) {
            agentTel = null;
        }
        userLoc.setUserAgentTel(agentTel);
        PreferenceTools.putString(USER_AGENT_TEL, agentTel);
        return true;
    }

    public boolean setBankLogo(String logoLink) {
        if (DxTextUtils.isEmpty(logoLink)) {
            logoLink = null;
        }
        userLoc.setBankLogo(logoLink);
        PreferenceTools.putString(USER_BANK_BANKLOGO, logoLink);
        return true;
    }

    /**
     * 设置用户位置经度
     * @param lon
     */
    public void setLocationLon(String lon){
        if(DxTextUtils.isEmpty(lon)){
            lon = null;
        }
        userLoc.setUserLon(lon);
        PreferenceTools.putString(USER_LOCATION_LON,lon);
    }
    public void setLocationLat(String lat){
        if(DxTextUtils.isEmpty(lat)){
            lat = null;
        }
        userLoc.setUserLat(lat);
        PreferenceTools.putString(USER_LOCATION_LAT,lat);
    }
    public boolean clearUserInfo(){
        userLoc = null ;
        return true;
    }
}

